package com.bdzl.flow.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bdzl.flow.dao.ActChkRecDao;
import com.bdzl.flow.service.ActChkRecService;
import com.bdzl.flow.servicefeign.AuthFeginService;
import com.bdzl.pub.entity.flow.ActChkRecDO;
import com.bdzl.pub.entity.sys.UserDO;
import com.bdzl.pub.vo.flow.ActChkRecVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;



@Service
public class ActChkRecServiceImpl implements ActChkRecService {
	@Autowired
	private ActChkRecDao actChkRecDao;
	@Autowired
	private AuthFeginService authFeginService;

	@Override
	public ActChkRecDO get(Integer acrId){
		return actChkRecDao.get(acrId);
	}

	@Override
	public List<ActChkRecVO> list(Map<String, Object> map){
		List<ActChkRecDO> actChkRecDOList = actChkRecDao.list(map);
		List<ActChkRecVO> actChkRecVOList = new ArrayList<>();
		if (actChkRecDOList.size()>0){
			for (ActChkRecDO actChkRecDO : actChkRecDOList) {
				ActChkRecVO actChkRecVO = new ActChkRecVO();
				//类拷贝
				BeanUtils.copyProperties(actChkRecDO, actChkRecVO);
				Object user = authFeginService.getUserById(actChkRecDO.getAcrOperator());
				// 将数据转成json字符串
				String jsonObject= JSON.toJSONString(user);
				//将json转成需要的对象
				UserDO userDO = JSONObject.parseObject(jsonObject, UserDO.class);
				actChkRecVO.setAcrOperatorName(userDO.getUserNickname());
				actChkRecVOList.add(actChkRecVO);
			}
		}
		return actChkRecVOList;
	}

	@Override
	public int count(Map<String, Object> map){
		return actChkRecDao.count(map);
	}

	@Override
	public int save(ActChkRecDO actChkRec){

		return actChkRecDao.save(actChkRec);
	}

	@Override
	public int update(ActChkRecDO actChkRec){
		return actChkRecDao.update(actChkRec);
	}

	@Override
	public int remove(Integer acrId){
		return actChkRecDao.remove(acrId);
	}

	@Override
	public int batchRemove(Integer[] acrIds){
		return actChkRecDao.batchRemove(acrIds);
	}

	@Override
	public List<ActChkRecDO> getByOdrNo(String acrOdr,Integer acrNodeId) {
		return actChkRecDao.getByOdrNo(acrOdr, acrNodeId);
	}

	@Override
	public List<ActChkRecVO> getActChkRecByOdrNoNotAcrNodeId(String odrNo, Integer acrNodeId) {
		return actChkRecDao.getActChkRecByOdrNoNotAcrNodeId(odrNo,acrNodeId);
	}

}
